<?php

namespace app\controller\api;

use app\controller\BaseController;
use plugin\admin\app\model\Lplog;
use support\Request;
use support\Response;

class LogController extends BaseController
{
    public function index(Request $request)
    {
        return response(__CLASS__);
    }

    /**
     * http://150.109.41.46:8787
     * http://150.109.41.46:8787/ddhdapi/log/record
     * http://goodvibeen.com/ddhdapi/log/record?a=b&c=d
     *
     * @param Request $request
     * @return Response
     */
    public function record(Request $request): Response
    {
        $time_int = time();
        $time_d2 = date('Ymd H:i:s',$time_int-16*3600);
        $time_d = date('Ymd',$time_int-16*3600);
        $row = [
            'd' => $time_d,
            'create_int' => time(),
            'params' => json_encode($request->all()),
            'header' => json_encode($request->header()),
            'type' => 1,
        ];

        Lplog::query()->create($row);

        return  $this->success(compact('time_int','time_d2'));
    }

}
